package org.itboys.admin.service.lasted;

import org.itboys.admin.entity.lasted.SystemRole;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.itboys.param.PageResult;
import org.itboys.param.ParamUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


/**
 * 作者：jiangxiong
 * 日期：2017年2月27日
 * 联系方式 ：empty90911@126.com
 * 描述：系统_角色_Service，江雄重新写的
 */
@Service
public class SystemRoleService extends BaseMongoService<SystemRole> {
    @Resource(name = "adminDS")
    private MongoDataSource ds;

    @Override
    protected MongoDataSource getMongoDataSource() {
        return ds;
    }

    @Override
    protected Class<SystemRole> getEntityClass() {
        return SystemRole.class;
    }
    /**
     * 修改或新增
     * @param role
     */
    public void saveRole(SystemRole role){
        if(role.getId()==0l){
            super.save(role);
        }else{
            super.updateExceptEmpty(role.getId(),role);
        }
    }

    /**
     * 分页获取
     * @param request
     * @return
     */
    public PageResult<SystemRole> selectRole(HttpServletRequest request){
        Map<String,Object> param =new HashMap<String, Object>();
        param.put("isDeleted", 0);
        Map<String,String> containsparam = ParamUtil.packageMongoVagueParam(request,"name");
        PageResult<SystemRole> result=super.containpageQuery(request,containsparam,param);
        return result;
    }




}
